package com.smooth.mall.utils;

import com.smooth.mall.common.Constant;
import org.apache.tomcat.util.codec.binary.Base64;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class MD5Utils {
    public static String getMD5Str(String strValue) throws NoSuchAlgorithmException {
        //使用MD5加密
        MessageDigest md5 = MessageDigest.getInstance("MD5");
        //返回转码后String类型
        return Base64.encodeBase64String(md5.digest((strValue + Constant.SALT).getBytes()));
    }

    public static void main(String[] args) {
        try {
            String md5Str = getMD5Str("12345");
            System.out.println(md5Str);
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
    }
}
